package com.tourism.service.impl;

import com.tourism.dao.AreaDao;
import com.tourism.entity.Area;
import com.tourism.exception.ExceptionEnum;
import com.tourism.exception.GlobalException;
import com.tourism.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author z
 * @Date 2021-04-25 9:10
 */
@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    private AreaDao areaDao;

    @Override
    public boolean addArea(Area area) throws GlobalException {
        Area data = areaDao.getAreaByName(area.getName());
        //不为空，则存在
        if (data != null) {
            throw new GlobalException(ExceptionEnum.AreaExist);

        }
        area.init();
        return areaDao.addArea(area);
    }

    @Override
    public List<Area> getAllArea(String name) {
        return areaDao.getAllArea(name);
    }
//删除地区
    @Override
    public Boolean deleteAreaById(Long id) {
        return areaDao.deleteAreaById(id);
    }
//修改地区
    @Override
    public boolean updateArea(Area area) {
        return areaDao.updateArea(area);
    }
}
